//
//  XYMainFrom.m
//  十年少
//
//  Created by 尧的mac on 15/11/28.
//  Copyright © 2015年 xxy.icom. All rights reserved.
//

#import "XYMainFrom.h"
#import "XYMainModel.h"
#import <UIKit/UIKit.h>
@implementation XYMainFrom

-(void)setMainModel:(XYMainModel *)mainModel{

    _mainModel = mainModel;
    
    CGFloat contentFloatwidth = [UIScreen mainScreen].bounds.size.width;
    CGSize titleSize = [self getBoundSize:16 headText:mainModel.title widthSize:MAXFLOAT];
    //标题
    self.titleFrom = CGRectMake((contentFloatwidth-titleSize.width)/2, 5, titleSize.width, titleSize.height);
    
    //分割线
    self.viewFrom = CGRectMake(0, CGRectGetMaxY(_titleFrom)+15, contentFloatwidth, 1);
    
    CGSize textSize =[self getBoundSize:15 headText:mainModel.text widthSize:contentFloatwidth-10];
    //正文
    self.textFrom =CGRectMake(6, CGRectGetMaxY(_viewFrom)+3, textSize.width, textSize.height+20);
    
    //时间
    CGSize timeSize =[self getBoundSize:12 headText:mainModel.ct widthSize:contentFloatwidth];
    self.ctFrom =CGRectMake(contentFloatwidth-timeSize.width, CGRectGetMaxY(_textFrom)+15, timeSize.width, timeSize.height);
    
    //尾部分隔线
    
    self.footFrom =CGRectMake(0, CGRectGetMaxY(_ctFrom)+10, contentFloatwidth, 1);
    
    self.cellHeight = CGRectGetMaxY(_footFrom);
}

/**
 *  根据文字多少自适应大小
 *
 *  @param charSize  文字大小
 *  @param headText  文字
 *  @param widthSize Lable最大宽
 *
 *  @return CGSize
 */
-(CGSize)getBoundSize:(CGFloat)charSize  headText:(NSString *)headText widthSize:(CGFloat)widthSize{
    
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    dict[NSFontAttributeName] = [UIFont systemFontOfSize:charSize];
    CGSize contentLabelSize = [headText boundingRectWithSize:CGSizeMake(widthSize, MAXFLOAT)options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
    return contentLabelSize;
}

@end
